//
//  UIBarButton+Extension.swift
//  YZXWeibo
//
//  Created by 叶周翔 on 16/7/23.
//  Copyright © 2016年 叶周翔. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(imageName:String){
        let btn = UIButton(type: UIButtonType.Custom)
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let imageHight = imageName + "_highlighted"
        btn.setImage(UIImage(named: imageHight), forState: UIControlState.Highlighted)
        // 自适应
        btn.sizeToFit()
        
        self.init(customView:btn)
    }
    
    
    convenience init(imageName:String,target: AnyObject?, action: Selector, tag: Int = 0){
        let btn = UIButton(type: UIButtonType.Custom)
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        let imageHight = imageName + "_highlighted"
        btn.setImage(UIImage(named: imageHight), forState: UIControlState.Highlighted)
        
        btn.tag = tag
        
        // 自适应
        btn.sizeToFit()
        
        // 点击事件
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        self.init(customView:btn)
    }
    
}